package ar.org.cfired.creditos;


import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.jbpm.api.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.Execution;
import org.jbpm.api.TaskService;
import org.jbpm.api.task.*;

import ar.org.cfired.hibernate.utils.HibernateUtil;
import ar.org.cfired.creditos.gui.Formulario;

public class PruebaAdjunto {
	public static void main (String args[]) {
	
			
			Integer cre_id = 139;
	    	Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			Transaction t = session.beginTransaction();
			
			 ProcessEngine processEngine = new Configuration().buildProcessEngine();
			 TaskService taskService = processEngine.getTaskService();
			 ExecutionService executionService = processEngine.getExecutionService();
			 
			Task tarea = taskService.getTask("521");
			System.out.println(tarea.getActivityName());
			System.out.println(tarea.getAssignee()); 
			Execution ex = executionService.findExecutionById(tarea.getExecutionId());
			System.out.println(ex.getId());
			
			System.out.println(ex.getProcessDefinitionId().substring(0,ex.getProcessDefinitionId().indexOf("-")));
			System.out.println(ex.getProcessInstance());
			//System.exit(0);
			 
			
			
			try {
				Formulario f = new Formulario(session, "ar/org/cfired/creditos/completarDatos.ftl", "cliente", "E", "Creditos", "Creditos-3", 3);
				//System.out.println(f.toOnLoadHTML()); 
				f.setBotonera("ABC");
				System.out.println(f.toHTML().substring(0,2500));
				//System.out.println(f.toHTML());
				/*Query q = session.createSQLQuery("exec jbpm4.dbo.gui_mostrar_solapas @seguridad = 3, @formulario = 'ar/org/cfired/creditos/SolicitudRecibida.ftl', @perfil = 'E', @proceso='Creditos', @version='Creditos v1.0.6', @usuario = 'fbarletta'");
				List<Object[]> listado = q.list();
				Iterator<Object[]> lista = listado.iterator();
				Object[] obj;
				while (lista.hasNext()) {
					obj = (Object[])lista.next();
					for (int i = 0; i<obj.length; i++) {
						System.out.println(obj[i].toString());
					}
				}*/
				
				/*List<Adjunto> listaAdjuntos = (List<Adjunto>)session.createQuery("from Adjunto where cre_id=" + cre_id).list();
				Iterator<Adjunto> adjuntos = listaAdjuntos.iterator();
				Adjunto adj = null;
				System.out.println("<table>");
				while (adjuntos.hasNext()) {
					adj = adjuntos.next();
					System.out.println("<tr><td><a onClick=\"document.getElementById('txtIdArchivo').value=" + adj.getAdjId() + "\" onMouseOver=\"this.style.cursor='hand'\" onMouseOut=\"this.style.cursor='default'\" >" + adj.getAdjDescripcion() + "</a></td><td>" + adj.getAdjUsuario() + "</td><td>" + adj.getAdjFecha().toString().substring(0, 10) + "</td></tr>");
				}
				System.out.println("</table>"); 
				*/
				t.rollback();
				
			}
			catch (HibernateException e){
				System.err.println(e.toString());
			}	
	}
}
